Skip to content

打开数据库 - OpenDatabase

函数简介

打开数据库,返回一个数据库对象指针。若文件不存在则返回失败。

接口名称

OpenDatabase

DLL调用

c
long OpenDatabase(long ola, string dbName, string password);

参数说明

参数名类型说明
ola长整数型OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。
dbName字符串数据库文件路径。
password字符串数据库密码。

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
long db = ola.OpenDatabase("data/app.db", "");
if (db != 0) {
    // db 为数据库连接句柄,用于 ExecuteSql / ExecuteReader
    ola.CloseDatabase(db);
}
csharp
using OLAPlug;

var ola = new OLAPlugServer();
long db = ola.OpenDatabase("data/app.db", "");
if (db != 0)
{
    // db 为数据库连接句柄,用于 ExecuteSql / ExecuteReader
    ola.CloseDatabase(db);
}
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
db = ola.OpenDatabase("data/app.db", "")
if db != 0:
    # db 为数据库连接句柄,用于 ExecuteSql / ExecuteReader
    ola.CloseDatabase(db)
java
import com.olaplug.OLAPlugServer;

OLAPlugServer ola = new OLAPlugServer();
long db = ola.OpenDatabase("data/app.db", "");
if (db != 0) {
    // db 为数据库连接句柄,用于 ExecuteSql / ExecuteReader
    ola.CloseDatabase(db);
}
cpp
var ola = com("OlaPlug.OlaSoft")
var db = ola.OpenDatabase("data/app.db", "")
if(db) {
    // db 为数据库连接句柄,用于 ExecuteSql / ExecuteReader
    ola.CloseDatabase(db)
}
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
db = ola.OpenDatabase("data/app.db", "")
If db <> 0 Then
    // db 为数据库连接句柄,用于 ExecuteSql / ExecuteReader
    ola.CloseDatabase(db)
End If
text
.局部变量 ola, OLAPlug
ola.创建 ()
db = ola.OpenDatabase (“data/app.db“, ““)
.如果真 (db ≠ 0)
    // db 为数据库连接句柄,用于 ExecuteSql / ExecuteReader
    ola.CloseDatabase (db)
.如果真结束
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var db = ola.OpenDatabase("data/app.db", "");
if(db){
    // db 为数据库连接句柄,用于 ExecuteSql / ExecuteReader
    ola.CloseDatabase(db);
}
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
长整数 db = ola.OpenDatabase("data/app.db", "")
如果真 (db ≠ 0)
{
    // db 为数据库连接句柄,用于 ExecuteSql / ExecuteReader
    ola.CloseDatabase(db)
}
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
long db = ola.OpenDatabase("data/app.db", "");
if (db != 0) {
    // db 为数据库连接句柄,用于 ExecuteSql / ExecuteReader
    ola.CloseDatabase(db);
}

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
long db = OpenDatabase(instance, "data/app.db", "");
if (db != 0) {
    // 使用 db 执行 SQL
    CloseDatabase(instance, db);
}
csharp
using System.Runtime.InteropServices;

[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();

long instance = CreateCOLAPlugInterFace();
long db = OpenDatabase(instance, "data/app.db", "");
if (db != 0)
{
    CloseDatabase(instance, db);
}
python
from ctypes import CDLL, c_int, c_int64

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
db = ola.OpenDatabase(instance, b"data/app.db", b"")
if db:
    ola.CloseDatabase(instance, db)

返回值

数据库对象指针。若打开失败,返回 0。